package com.xia.manager.rpc;

import com.cy.api.ProductRpc;
import com.cy.api.domain.ProductRpcReq;
import com.cy.entity.Product;
import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl;
import com.xia.manager.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ProductRpcImpl
 * @Deserintion RPC服务实现类
 * @Author ciyuan
 * @Date 2018/12/3/003 0:08
 **/
@Slf4j
@AutoJsonRpcServiceImpl
@Service(value = "ProductRpc")
public class ProductRpcImpl implements ProductRpc {

    @Autowired
    private ProductService productService;

    @Override
    public List<Product> query(ProductRpcReq req) {
        log.info("查询多个产品，请求=【{}】",req);
        Pageable pageable = new PageRequest(0, 100, Sort.Direction.DESC, "rewardRate");
        Page<Product> page = productService.query(req.getIdList(), req.getMinRewardRate(), req.getMaxRewardRate(), req.getStatusList(), pageable);
        log.info("查询多个产品，结果=【{}】",page);
        return page.getContent();
    }

    @Override
    public Product findOne(String id) {
        log.info("查询单个产品详情，请求=【{}】",id);
        Product product = productService.findOne(id);
        log.info("查询单个产品详情，结果=【{}】",product);
        return product;
    }
}
